//
//  SaViewControllerUtils.m
//  saas
//
//  Created by fangyibao on 2019/10/10.
//  Copyright © 2019 fangmao. All rights reserved.
//

#import "SaViewControllerUtils.h"
#import "UIViewController+Saas.h"
#import "ViewController.h"
//#import "SaUserDataCenter.h"
#import "AppDelegate.h"
@implementation SaViewControllerUtils
+ (void)needLogin{
//    [self showAlert:@{@"title":@"登录提示", @"message":@"当前没有用户登录，是否前往登录?", @"confirm":@"登录", @"cancel":@"取消"} cancel:nil confirm:^{
//        ViewController *loginVC = [ViewController new];
//        loginVC.hidesBottomBarWhenPushed = YES;
//
//        [[self currentViewController].navigationController pushViewController:loginVC animated:YES];
//        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
//        [defaults setObject:@(0) forKey:@"isLogin"];
//        
//        
////        [SaUserDataCenter shareIntance].isLogin = NO;
////        [[SaUserDataCenter shareIntance] save];
////        [[AppDelegate shareInstance] application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:nil];
//    }];
    [LUtilityTools showAlertWithTitle:@"温馨提示" message:@"当前没有用户登录，是否前往登录?" cancelTitle:@"不了" buttonAction:^{
        
    } sureTitle:@"去登录" ButtonAction:^{
                ViewController *loginVC = [ViewController new];
                loginVC.hidesBottomBarWhenPushed = YES;
        
                [[self currentViewController].navigationController pushViewController:loginVC animated:YES];
                NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:@(0) forKey:@"isLogin"];
        
        
        //        [SaUserDataCenter shareIntance].isLogin = NO;
        //        [[SaUserDataCenter shareIntance] save];
        //        [[AppDelegate shareInstance] application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:nil];
    }];
    
    
    
    
}
+(UIViewController *)currentViewController{
    return [UIViewController findBestViewController:[self getWindow].rootViewController];
}
+ (UIWindow *)getWindow{
    return [UIApplication sharedApplication].keyWindow;
}
+ (void)showAlert:(NSDictionary *)alert cancel:(void (^)())cancel confirm:(void (^)())confirm{
    [[self currentViewController] showAlert:alert cancel:cancel confirm:confirm];
}
@end
